package club.twelveblog.tblog.common.config;

import club.twelveblog.tblog.interceptor.BlogInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 设置拦截器
 */
@Configuration
public class MyBlogWebMvcConfigurer implements WebMvcConfigurer {
    @Autowired
    private BlogInterceptor blogInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加一个拦截器，拦截以/tblog/admin为前缀的url路径
        registry.addInterceptor(blogInterceptor)
                .addPathPatterns("/tblog/admin/**")
                .excludePathPatterns("/addCategory")
                .excludePathPatterns("/findAllUser")
                .excludePathPatterns("/updateAdminImg")
                .excludePathPatterns("/userStatus");
        registry.addInterceptor(blogInterceptor)
                .addPathPatterns("/tblog/user/**")
                .excludePathPatterns("/show")
                .excludePathPatterns("/editArticle")
                .excludePathPatterns("/icon")
                .excludePathPatterns("/article")
                .excludePathPatterns("/myComment");
        registry.addInterceptor(blogInterceptor)
                .addPathPatterns("/tblog/comment/**")
                .addPathPatterns("/tblog/blogInfo/updateArticle")//更新博客
                .addPathPatterns("/tblog/blogInfo/banComment")
                .addPathPatterns("/tblog/blogInfo/deleteArticle");//禁止评论

    }
}
